package com.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.beans.Movie;
import com.bussiness.AdminBussinessProxy;
import com.constants.ServiceEndPoints;
import com.constants.UIMessages;

/**
 * Servlet implementation class MovieReportTypeServlet
 */
public class MovieReportTypeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	AdminBussinessProxy adminBI = new AdminBussinessProxy();   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MovieReportTypeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		RequestDispatcher dispatcher;
		Movie[] movie = null;
		Movie m =null;
		String[] ids;
		
		try
		{
			
			String type = request.getParameter("typeid");
			adminBI.setEndpoint(ServiceEndPoints.AdminEndPoint);
			System.out.println("in catid type:"+type);
			movie = adminBI.getMovieByCategory(type);
			session.setAttribute("selectedTypeMovies", movie);
			dispatcher = getServletContext().getRequestDispatcher("/reportbytype.jsp");
			dispatcher.forward(request, response);
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
			request.setAttribute("ServerMessage", UIMessages.SERVICE_UNAVAILABLE);
			dispatcher = getServletContext().getRequestDispatcher("/reportbytype.jsp");
			dispatcher.forward(request, response);
		}
	

	
	}
	

}
